package com.getpebble.android.notifications.util;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import com.getpebble.android.PebbleApplication;
import com.getpebble.android.common.core.trace.Trace;

public class AndroidAppInstallListener extends BroadcastReceiver {
    private static final String TAG = AndroidAppInstallListener.class.getSimpleName();

    public AndroidAppInstallListener() {
        IntentFilter filter = new IntentFilter();
        filter.addAction("android.intent.action.PACKAGE_ADDED");
        filter.addAction("android.intent.action.PACKAGE_REMOVED");
        filter.addDataScheme("package");
        Trace.debug(TAG, "Registering receiver");
        PebbleApplication.getAppContext().registerReceiver(this, filter);
    }

    public void onReceive(Context context, Intent intent) {
        Trace.debug(TAG, "onReceive intent = " + intent + " dataString = " + intent.getDataString());
        NotificationUtil.loadAndroidApps();
    }

    public void destroy() {
        PebbleApplication.getAppContext().unregisterReceiver(this);
    }
}
